package com.dyp.mapstructdemo;

import com.dyp.mapstructdemo.domain.Company;
import com.dyp.mapstructdemo.domain.Person;
import com.dyp.mapstructdemo.service.dto.CompanyDTO;
import com.dyp.mapstructdemo.service.mapper.CompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class MapStructDemoApplication implements CommandLineRunner {

	public static void main(String[] args) {
		SpringApplication.run(MapStructDemoApplication.class, args);
	}
    @Autowired
	CompanyMapper companyMapper;
	@Override
	public void run(String... args) throws Exception {
		Company company = new Company();
		company.setId(1l);
		company.setName("dyp company");
		company.setIsDisable(false);
		company.setPostalCode("710000");
		company.setStreetAddress("company address a");

		Person person = new Person();
		person.setId(1l);
		person.setName("person name");
		person.setLocal("local");
		List<Person> personList = new ArrayList<>();
		personList.add(person);
		company.setPersons(personList);
		System.out.println(company.toString());
		CompanyDTO companyDTO = companyMapper.toDto(company);

		System.out.println(companyDTO.toString());
	}
}
